package com.hnhcyy.goods.mapper;

import java.util.HashMap;
import java.util.List;

import com.hnhcyy.goods.pojo.Goods;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.hnhcyy.goods.pojo.GoodsExtend;

/**
 * 商品扩展属性
 * @author sheyongjun  
 * @date 2019年2月16日
 */
public interface GoodsExtendMapper {
	
	/**
	 * 查询商品扩展记录
	 * @param sjid
	 * @param spid
	 * @return
	 */
	GoodsExtend selectItemBySjidAndSpid(@Param("sjid") Integer sjid, @Param("spid") String spid);
	
	/**
	 * 查询是否有记录
	 * @author sheyongjun
	 * @date 2019年2月26日
	 */
	int selectCountBySjidAndSpid(@Param("sjid") Integer sjid, @Param("spid") String spid);
	
	/**
	 * 更新商品扩展表信息
	 * @param goodsExtend
	 * @return
	 */
	int updateItem(GoodsExtend goodsExtend);
	
	/**
	 * 查询所有上架的商品ID
	 * @author sheyongjun
	 * @date 2019年3月12日
	 */
	List<String> selectSpidListOnSell();

	@Insert("insert into goods_extend(sjid,spid,isvisible,xsqy,findex,hotsell,gross_profit,new_starttime,new_endtime)"+
			" values (#{sjid},#{spid},ifnull(#{isvisible},0),ifnull(#{xsqy},'0000000000000000000000000000000000'),ifnull(#{findex},0),"+
			"ifnull(#{hotsell},0),ifnull(#{grossProfit},0.0),#{newStarttime},#{newEndtime})")
	public int insertItem(GoodsExtend item);
	
	@Select("select * from goods_extend where sjid=#{sjid} and spid=#{spid} limit 1")
	public HashMap get(int sjid, String spid);
	
	@Select("select * from goods_extend")
	public List<HashMap> getall();
	
	@Select("select spid from goods_extend where isVisible=1 and sjid=#{sjid} and spid in(select spid from sp_old_mchk where sjid=#{sjid} and dwbh=#{dwbh} and fenable=1)")
	public List<String> getSpidsOldMchk(int sjid, String dwbh);
	
	@Select("select spid from goods_extend where isVisible=1 and sjid=#{sjid} and xsqy != '0000000000000000000000000000000000'")
	public List<String> getSpidsTestMchk(int sjid, String dwbh);
	
	@Select("select spid from goods_extend where isVisible=1 and sjid=#{sjid}"+
			" and (substring(xsqy,#{qyid},1)='1'"+
			" or spid in(select spid from sp_mchk where sjid=#{sjid} and dwbh=#{dwbh} and fenable=1))"+
			" and spid not in(select spid from sp_mchk where sjid=#{sjid} and dwbh=#{dwbh} and fenable=0)")
	public List<String> getSpidsMchk(int sjid,int qyid,String dwbh);
	
	/**
	 * 更新即将涨价字段
	 * @param goodsExtend
	 * @return
	 */
	public int updateRiseInPrice(GoodsExtend goodsExtend);

}
